package com.soso.base.filter;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

public class ETagResponseStream extends ServletOutputStream {
        
        private boolean closed = false;
        private OutputStream stream = null;

        public ETagResponseStream(HttpServletResponse response, OutputStream stream) throws IOException {
                super();
                this.stream = stream;
        }

        public void close() throws IOException {
                if (!closed) {
                        stream.close();
                        closed = true;
                }
        }

        public void flush() throws IOException {
                if (!closed) {
                        stream.flush();
                }
        }

        public void write(int b) throws IOException {
                if (!closed) {
                        stream.write((byte) b);
                }
        }

        public void write(byte b[], int off, int len) throws IOException {
                if (!closed) {
                        stream.write(b, off, len);
                }
        }

        public void write(byte b[]) throws IOException {
                write(b, 0, b.length);
        }

        public boolean closed() {
                return closed;
        }

        public void reset() {
                //noop
        }
}